# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://coffeescript.org/
@App.controller 'TodoCtrl', ($scope, TodoItem) ->
  $scope.todos = TodoItem.query()
  $scope.todoitem = {title: '', is_complete: false}

  $scope.allToggle = false

  $scope.addTodo = ->
    todo = TodoItem.save($scope.todoitem, (val) ->
      $scope.todos.push(todo)
      $scope.todoitem = {title: '', is_complete: false}
    ,
    (data) ->
      alert('创建失败.')
    )

  $scope.toggleAll = ->
    $scope.todos.forEach((todo, i) ->
      todo.is_complete = $scope.allToggle
    )
